package com.distribute.framework.model;

import com.distribute.framework.core.web.helper.Utils;
import com.distribute.framework.core.lang.*;


public enum SystemModelClass{
	TbMsg(TbMsg.class),
	TbReturnCoupon(TbReturnCoupon.class),
	TbThreeCity(TbThreeCity.class),
	TbActivityText(TbActivityText.class),
	TbCarouselConfig(TbCarouselConfig.class),
	TbPosterImages(TbPosterImages.class),
	TbShareConfig(TbShareConfig.class),
	TbOfficialWechat(TbOfficialWechat.class),
	TbBrandStory(TbBrandStory.class),
	TbOfflineZs(TbOfflineZs.class),
	TbCardBinding(TbCardBinding.class),
	TbBalanceStatistics(TbBalanceStatistics.class),
	BrandDrawal(BrandDrawal.class),
	TbSecondCity(TbSecondCity.class),
	TbPartnerCardOrder(TbPartnerCardOrder.class),
	TbOrderInvoies(TbOrderInvoies.class),
	TbJxshIncome(TbJxshIncome.class),
	TbPartnerIncome(TbPartnerIncome.class),
	TbPartnerConfig(TbPartnerConfig.class),
	TbPartners(TbPartners.class),
	TbJxsh(TbJxsh.class),
	Parameter(Parameter.class),
	DistributorIncome(DistributorIncome.class),
	DistributorCash(DistributorCash.class),
	Replenishment(Replenishment.class),
	Replenish(Replenish.class),
	Distributor(Distributor.class),
	Agent(Agent.class),
	AgentCardOrder(AgentCardOrder.class),
	AgentCard(AgentCard.class),
	AgentConf(AgentConf.class),
	BrandAccount(BrandAccount.class),
	MembershipRecord(MembershipRecord.class),
	IncomeRecord(IncomeRecord.class),
	Account(Account.class),
	Configur(Configur.class),
	Headline(Headline.class),
	Region(Region.class),
	HelpCategory(HelpCategory.class),
	OrderDetails(OrderDetails.class),
	DirectOrder(DirectOrder.class),
	Unit(Unit.class),
	Option(Option.class),
	Spec(Spec.class),
	Higher(Higher.class),
	Commodity(Commodity.class),
	ProductDetails(ProductDetails.class),
	BalanceDetails(BalanceDetails.class),
	PackRecord(PackRecord.class),
	Product(Product.class),
	ProductOrder(ProductOrder.class),
	RedPacket(RedPacket.class),
	Coupon(Coupon.class),
	OfflineCoupon(OfflineCoupon.class),
	HeedCoupon(HeedCoupon.class),
	InvitCoupon(InvitCoupon.class),
	NewGifts(NewGifts.class),
	DirectCoupon(DirectCoupon.class),
	InvitationQrCode(InvitationQrCode.class),
	ShoppingCart(ShoppingCart.class),
	UserAddress(UserAddress.class),
	InvitRecord(InvitRecord.class),
	Feedback(Feedback.class),
	Member(Member.class),
	BrandApplication(BrandApplication.class),
	BindingDistributor(BindingDistributor.class),
	Manage(Manage.class),
	ManageRole(ManageRole.class),
	Merchant(Merchant.class),
	SrvLogin(SrvLogin.class),
	SrvRole(SrvRole.class),
	SrvApiLog(SrvApiLog.class),
	SrvApiType(SrvApiType.class),
	SrvApiClient(SrvApiClient.class),
	SrvApi(SrvApi.class),
	SrvOauth(SrvOauth.class),
	SrvHost(SrvHost.class),
	SrvLog(SrvLog.class),
	SrvTodo(SrvTodo.class),
	SrvEventHeed(SrvEventHeed.class),
	SrvEventType(SrvEventType.class),
	SrvEvent(SrvEvent.class),
	SrvSql(SrvSql.class),
	SrvError(SrvError.class),
	SrvAttribute(SrvAttribute.class),
	SrvQuery(SrvQuery.class),
	SrvArgument(SrvArgument.class),
	SrvProperty(SrvProperty.class),
	SrvUser(SrvUser.class),
	SrvGroup(SrvGroup.class),
	SrvProject(SrvProject.class),
	SrvLimited(SrvLimited.class),
	;private Class value;
	private SystemModelClass(Class value) {
		this.value = value;
	}
	public String getName(){
		return this.name();
	}
	public Class getValue(){
		return this.value;
	}
	public String getCaption(){
		caption caption = (caption) this.value.getAnnotation(caption.class);
		return caption.value();
	}
	public String getNamespace(){
		namespace namespace = (namespace) this.value.getAnnotation(namespace.class);
		return namespace.value();
	}
	public static SystemModelClass[] getModels(String modelNames){
		if(Utils.empty(modelNames))
			return SystemModelClass.values();
		String[] names = modelNames.split(",");
		java.util.List models = new java.util.ArrayList();
		for(int i=0;i<names.length;i++){
			try{
				models.add(SystemModelClass.valueOf(names[i]));
			}catch(Exception ex){
	 			ex.printStackTrace();
	 		}
		}
		return (SystemModelClass[]) models.toArray(new SystemModelClass[]{});
	}
	public static SystemModelClass getModel(String modelName){
		return SystemModelClass.valueOf(modelName);
	}
	public static <T> T getGenericObject(String classAtValue){
		if(Utils.empty(classAtValue))
 			return null;
 		try{
	 		String ClassName = classAtValue.split("@")[0];
	 		Long id = Long.parseLong(classAtValue.split("@")[1]);
	 		Class<?> cls = Class.forName("com.distribute.framework.model."+ClassName);
	 		return (T) cls.getMethod("get", Long.class).invoke(null, id);
 		}catch(Exception ex){
 			ex.printStackTrace();
 			return null;
 		}
	}
	public static String getGenericValue(String classAtValue){
 		try{	
 			Object object = getGenericObject(classAtValue);
 			if(object==null)return null;
 			String strValue="";
	 		caption caption = object.getClass().getAnnotation(caption.class);
	 		if(caption!=null)
	 			strValue+="["+caption.value()+"]";
	 		try {
				strValue+=object.getClass().getMethod("getKeyValue").invoke(object);
				return strValue;
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}
 		}catch(Exception ex){
 			ex.printStackTrace();
 			return null;
 		}
	}
}
